package com.xiaofei.masterwork;

import java.util.Map;
import java.util.Queue;

public abstract class AbstractWorker implements Runnable{
	private Queue<Object>workQueue;
	private Map<String, Object>resultMap;
	
	//具体的处理逻辑
	public abstract Object Handler(Object input);
	
	public void setWorkQueue(Queue<Object> workQueue) {
		this.workQueue = workQueue;
	}
	
	public void setResultMap(Map<String, Object> resultMap) {
		this.resultMap = resultMap;
	}
	
	@Override
	public void run() {
		while(true){
			Object input = workQueue.poll();
			//所有任务已处理完毕
			if(null==input){
				break;
			}
			Object result = this.Handler(input);
			resultMap.put(Integer.toString(input.hashCode()), result);
		}
		
	}

}
